package cn.wancat.letcode;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class LetCode1389 {
    public static void main(String[] args) {
        int[] nums = {0,1,2,3,4};
        int[] index = {0,1,2,2,1};

        System.out.println(Arrays.toString(createTargetArray(nums,index)));

    }

    public static int[] createTargetArray(int[] nums, int[] index) {


//        int max = 0;
//        for(int i = 0; i<index.length;i++){
//            if(index[i]>max) max = index[i];
//        }

        LinkedList<Integer> linkedList = new LinkedList<>();
        for(int i = 0;i<index.length;i++){
            linkedList.add(index[i],nums[i]);
        }
        int[] re = new int[linkedList.size()];
        for(int i = 0;i<linkedList.size();i++){
            re[i] = linkedList.get(i).intValue();
        }
        return re;
    }
}
